//
//  DetailCellOne.swift
//  CompareBuying
//
//  Created by 唐先才 on 16/2/16.
//  Copyright © 2016年 唐先才. All rights reserved.
//

import UIKit

class DetailCellOne: UITableViewCell {
    
    @IBOutlet weak var titleLab: UILabel!
    @IBOutlet weak var priceLab: UILabel!
    @IBOutlet weak var mallLab: UILabel!
    
    var nationLab: UILabel?
    
    override func awakeFromNib() {
        super.awakeFromNib()
        nationLab = UILabel(frame: CGRect(x: WIDTH - 100, y: 100 - 15 - 10, width: 60, height: 15))
    }

    func configCellWithModel(model: TxcModel) {
        titleLab.text = model.InfoTitle
        priceLab.text = model.CommodityPrice
        guard let nationLab = nationLab, name = model.MallName else {
            return
        }
        if model.MallName == "" {
            mallLab.text = ""
        } else {
            mallLab.text = name + "供货"
        }
        if model.InfoNation == 2 {
            nationLab.backgroundColor = UIColor(red: 89 / 255, green: 160 / 255, blue: 130 / 225, alpha: 0.8)
            nationLab.text = "海外直发"
            nationLab.font = UIFont.systemFontOfSize(11)
            nationLab.layer.cornerRadius = 2
            nationLab.clipsToBounds = true
            nationLab.textAlignment = NSTextAlignment.Center
            self.contentView.addSubview(nationLab)
        }
    }

    static func detailCellOneWith(tableView: UITableView, dataArray: NSMutableArray, indexPath: NSIndexPath) -> UITableViewCell {
        if let detailCellOne = tableView.dequeueReusableCellWithIdentifier("detailCellOne") as? DetailCellOne {
            if dataArray.count > 0 {
                if let model = dataArray[indexPath.row] as? TxcModel {
                    detailCellOne.configCellWithModel(model)
                }
            }
            return detailCellOne
        }
        return UITableViewCell()
    }
    
    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }
    
//    lazy var nationLab: UILabel = {
//        let sub = UILabel(frame: CGRect(x: WIDTH - 140, y: self.contentView.frame.size.height - 15 - 10, width: 60, height: 15))
//        return sub
//    }()
    
}
